import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import { initMenu, getUrlParams } from './utils/Utils'

window.$ = window.jQuery = require("jquery");

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
ElementUI.Input.props.clearable.default=true;
ElementUI.Radio.props.size.default='small';
// Vue.use(Element, { size: 'small' });
Vue.use(ElementUI, { size: 'small' });

import echarts from 'echarts'
Vue.prototype.$echarts = echarts

import moment from 'moment'
Date.prototype.toISOString = function(){ 
    return moment(this).format('YYYY-MM-DD HH:mm:ss')
} 
Vue.prototype.$moment = moment

// 全局scss样式
import '@/assets/scss/variable.scss';
import '@/assets/scss/base.scss';
import '@/assets/scss/common.scss';
//全局插件
import GlogalPlugin from "./utils/GlogalPlugin";
Vue.use(GlogalPlugin);
//初始化项目插件
import AppInit from './utils/AppInit'
Vue.use(AppInit);

Vue.config.productionTip = false



// 全局路由守卫 监控点击路由之前
router.beforeEach((to, from, next)=>{
    window.localStorage.setItem('tenantCode', getUrlParams()['zh']||'daying');
    if (window.localStorage.getItem('token')) {
        initMenu(router, store);
        next();
    } else {
        if (to.path == '/') {
            next();
        }
        else {
            next('/?redirect=' + to.path);
        }
    }
})

function createApp() {
    new Vue({
        router,
        store,
        render: h => h(App),
        created() {
            document.title = '环策环保管理系统';
        }
    }).$mount('#app')
}

function appLoader() {
    //加载 请求和响应 拦截器
    AppInit.axiosInterceptors();
    //页面初始化配置js
    AppInit.loadConfig().then((result) => {
        let _baseConfig = eval(result._base_config);
        let _navConfig = eval(result._nav_config);
        let _industryConfig = eval(result._industry_config);
        let _wasteMaterialConfig = eval(result._wasteMaterial_config);
        let _downloadConfig = eval(result._download_config);
        Vue.prototype.$BASE = _baseConfig
        Vue.prototype.$NAV = _navConfig;
        Vue.prototype.$INDUSTRY = _industryConfig;
        Vue.prototype.$WASTE = _wasteMaterialConfig;
        Vue.prototype.$DOWNLOAD = _downloadConfig;
        createApp();
    }).catch(err => {
        alert("前端配置文件获取失败，", err);
    })
}

appLoader();
